package com.zhou.common.operator.log.core.resolver;

import com.zhou.common.operator.log.core.model.PrincipalInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public abstract class AbstractHttpServletRequestPrincipalResolver implements PrincipalResolver {

    @Override
    public PrincipalInfo resolvePrincipal(ProceedingJoinPoint joinPoint, Object[] arguments) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return this.resolveWithRequest(requestAttributes.getRequest());
    }

    protected abstract PrincipalInfo resolveWithRequest(HttpServletRequest request);
}
